﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Clueless
{
    public class Room
    {
        private String name; // Room name
        private LinkedList<Room> neighboringRooms;  // The neighoring rooms with paths from/to this room
        private RoomType roomType;  // The type of the room.
        private bool occupied;  // Is the room occupied?  Irrelevant for Rooms.

        /// <summary>
        ///     Constructor for a Room.
        /// </summary>
        /// <param name="roomName">The name of the room to be added.</param>
        /// <param name="type">The type of room.</param>
        public Room(String roomName, RoomType type)
        {
            neighboringRooms = new LinkedList<Room>();
            name = roomName;
            roomType = type;
        }
    
        /// <summary>
        ///     Retruns/Sets the name of the room.
        /// </summary>
        public String Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }

        /// <summary>
        ///     Returns the list of neighboring rooms
        /// </summary>
        public LinkedList<Room> NeighboringRooms
        {
            get
            {
                return neighboringRooms;
            }
            set
            {
                throw new System.NotImplementedException();
            }
        }

        /// <summary>
        ///     Returns the type of the room. Hall or Room.
        ///     <seealso cref="RoomType">See RoomType</seealso>
        /// </summary>
        public RoomType RoomType
        {
            get
            {
                return roomType;
            }
            set
            {
                throw new System.NotImplementedException();
            }
        }

        /// <summary>
        ///     Returns if the room is currently occupied
        /// </summary>
        /// <remarks>
        ///     Not sure if this is necessary
        /// </remarks>
        public bool Occupied
        {
            get
            {
                return occupied;
            }
            set
            {
                occupied = value;
            }
        }

        /// <summary>
        ///     Returns if the room is occupied
        /// </summary>
        /// <returns>
        ///     true - room is occupied
        ///     false - room is NOT occupied
        /// </returns>
        public bool isOccupied()
        {
            return occupied;
        }

        /// <summary>
        ///     Determines if this room is a hallway.
        /// </summary>
        /// <returns>
        ///     true - this room is a hallway
        ///     false - this room is NOT a hallway
        /// </returns>
        public bool isHall()
        {
            return (this.roomType == RoomType.Hallway); 
        }

        /// <summary>
        ///     Adds a neighbor the list of known neighbors
        /// </summary>
        /// <param name="r">The new room to added</param>
        public void AddNeighbor(Room r)
        {
            neighboringRooms.AddLast(r);
        }


        /// <summary>
        /// Determine if the given room is a neighbor
        /// </summary>
        /// <param name="r"></param>
        /// <returns></returns>
        public bool IsNeighbor(Room r)
        {
            foreach (Room n in NeighboringRooms)
            {
                if (n.Name == r.Name)
                {
                    return true;
                }
            }

            return false;
        }
    }
}
